(function($, window) {
	var echartFactory = window.echartFactory = {};

	/*
	 * 柱状图
	 
	 * 
	 data :{
	 	title:"",
	 	color:[],
	 	legendData:[],
	 	seriesData:[],
	 	xAxis:{
	 		name:"",
	 		type:"",     //"value"或者 "category"
	 		data:[]      //type是category是才有data
	 	},
	 	yAxis:{
	 		name:"",
	 		type:"",
	 		data:[]
	 	},
	 	itemStyleFormatter:function    //function(a,b,c,d){return a.name}
	 }
	 * **/
	echartFactory.createBarGraphOption = function(chartDataKey) {
		return function() {
			var data = this[chartDataKey];
			return {
				title: {
					subtext: data.title,
					subtextStyle: {
						color: "#5B5B5B"
					},
					x: 'center',
					y: -20
				},
				color: data.color,
				grid: {
					x: 20,
					y: 20,
					x2: 40,
					y2: 30,
					borderColor: 'rgba(0,0,0,0)'
				},
				calculable: false,

				xAxis: [{
					type: data.xAxis.type,
					name: data.xAxis.name,
					nameLocation: 'end',
					nameGap: 1,
					splitLine: {
						show: false,
						lineStyle: {
							color: '#373737',
							type: 'solid',
							width: 1
						}
					},
					splitArea: {
						areaStyle: {
							color: '#174686'
						}
					},
					axisLine: {
						show: true,
						lineStyle: {
							color: '#373737',
							width: 1
						}
					},
					axisLabel: {
						formatter: function(data) {
							var dataStr = String(data);
							if(dataStr.indexOf(".") > 0) {
								return "";
							}
							return data;
						}
					},
					data: data.xAxis.data
				}],
				yAxis: [{
					show: true,
					type: data.yAxis.type,
					name: data.yAxis.name,
					boundaryGap: true,
					data: data.yAxis.data,
					axisLabel: {
						show: false,
						textStyle: {
							color: "#80878c"
						}
					},
					splitLine: {
						show: false
					},
					splitArea: {
						areaStyle: {
							color: '#174686'
						}
					},
					axisLine: {
						show: true,
						lineStyle: {
							color: '#373737',
							width: 1
						}
					}
				}],
				series: [{
					type: 'bar',
					data: data.seriesData,
					itemStyle: {
						normal: {
							label: {
								show: true,
								position: 'insideLeft',
								formatter: data.itemStyleFormatter,
								textStyle: {
									color: "#000"
								}
							}
						},
						emphasis: {
							label: {
								show: true,
								formatter: data.itemStyleFormatter,
								textStyle: {
									color: "#000"
								}
							}
						}
					}
				}]
			};
		};
	}

	/*
	 * 饼状图
	 data:{
		title:"",
	 	color:[],
	 	legendData:[],
	 	seriesData:[],
	 	seriesLabelFormatter:function
	 }
	 */
	echartFactory.createPieChartOption = function(chartDataKey) {
		return function() {
			var data = this[chartDataKey];
			return {
				title: {
					//text: data.title || "ghjhgjghj",
					subtext: data.title || "",
					subtextStyle: {
						color: "#5B5B5B",
					},
					x: 'center',
					y: -25
				},
				legend: {
					orient: 'vertical',
					x: 'left',
					y: 'center',
					data: data.legendData
				},
				color: data.color,
				calculable: false,
				series: [{
					type: 'pie',
					radius: '75%',
					center: data.legendData ? ['71%', '50%'] : ['50%', '50%'],
					itemStyle: {
						normal: {
							borderColor: "#FFF",
							borderWidth: 1,
							labelLine: {
								show: false
							},
							label: {
								position: "inner",
								formatter: data.seriesLabelFormatter || function(a, b, c, d) {
									if(a.percent > 5) {
										return Math.round(a.percent) + "%";
									} else {
										return "";
									}
								}
							}
						}
					},
					data: data.seriesData
				}]
			};
		}
	};

	/*
	 data :{
	 	seriesData:[],    //[12,12,24,45]
	 	yAxisData:[],
	 	markPointData:[]   //["信道1","信道2"]

	 * */
	//无线环境信道
	echartFactory.createChannelBarGraphChartOption = function(chartDataKey) {
		return function() {
			var data = this[chartDataKey];
			var len = data.seriesData.length;
			return {
				grid: {
					containLabel: true,
					borderWidth: 0,
					x: 0,
					y: 10,
					y2: 0,
					x2: 40
				},
				xAxis: [{
					show: false,
					type: 'value',
					min: -10,
					max: 100
				}],
				yAxis: [{
					type: 'category',
					axisLine: {
						show: false
					},
					axisTick: {
						show: false
					},
					splitArea: {
						show: false
					},
					splitLine: {
						show: false
					},
					data: data.yAxisData
					//					data: (function() {
					//						var res = [];
					//						for(var i = len - 1; i >= 0; i--) {
					//
					//							var colorChannel = '#131a2d';
					//							if(data[i].ChlNum === dataInfo.CurChannel) {
					//								colorChannel = '#69c4c5';
					//							}
					//
					//							var item = {
					//								value: '信道' + data[i].ChlNum,
					//								textStyle: {
					//									color: colorChannel,
					//									fontFamily: 'Arial'
					//								}
					//							};
					//							res.push(item);
					//						}
					//						return res;
					//					})()
				}],
				series: [{
					name: '5G',
					barCategoryGap: (40 + (13 - len) * 4) + '%',
					type: 'bar',
					barWidth: 20,
					itemStyle: {
						normal: {
							color: function(params) {
								if(params.data >= 90) {
									return '#69d0d1';
								} else if(params.data >= 50) {
									return '#F5B638';
								} else {
									return '#e64c65';
								}
							},
							barBorderRadius: [15, 15, 15, 15],
							label: {
								show: true,
								position: 'right',
								formatter: '{c}',
								textStyle: {
									fontFamily: 'arial',
									fontSize: 11
								}
							}
						}
					},
					data: data.seriesData,
					markLine: {
						symbol: 'circle',
						symbolSize: 0,
						itemStyle: {
							normal: {
								color: '#000',
								lineStyle: {
									color: '#000',
									type: 'dashed',
									width: 0.5
								}
							}
						},
						data: [
							[{
									name: '',
									xAxis: -5,
									yAxis: len - 1
								}, // 当xAxis为类目轴时，数值1会被理解为类目轴的index，通过xAxis:-1|MAXNUMBER可以让线到达grid边缘
								{
									name: '',
									xAxis: -5,
									yAxis: 0
								}, // 当xAxis为类目轴时，字符串'周三'会被理解为与类目轴的文本进行匹配
							]
						]
					},
					markPoint: {
						symbol: 'circle',
						symbolSize: 3,
						itemStyle: {
							normal: {
								color: function(params) {
									if(data.seriesData[params.dataIndex] >= 90) {
										return '#69d0d1';
									} else if(data.seriesData[params.dataIndex] >= 50) {
										return '#F5B638';
									} else {
										return '#e64c65';
									}
								},
								borderWidth: 0,
								label: {
									show: false
								}
							}
						},
						data: data.markPointData
						//						data: (function() {
						//							var point = [];
						//							for(var i = 0; i < len; i++) {
						//
						//								var element = {
						//									xAxis: -5,
						//									yAxis: i,
						//									name: '信道' + data[len - i - 1].ChlNum
						//								};
						//								point.push(element);
						//							}
						//							return point;
						//						})()
					}
				}]
			};
		}
	}

	/*
	 
	 * 
	 * 
	 * 
	 * */
	echartFactory.createLineChartOption = function(chartDataKey) {
		return function() {
			var data = this[chartDataKey];
			return {
				xAxis: {
					type: 'category',
					data: data.xAxisData
				},
				yAxis: {
					type: 'value'
				},
				series: [{
					data: data.seriesData,
					type: 'line'
				}]
			};
		}
	}

})(mui, window);